package cn.edu.scnu.springbootcinema.service;

import cn.edu.scnu.springbootcinema.entity.Comments;
import cn.edu.scnu.springbootcinema.mapper.CommentsMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;

@Service
public class CommentsService extends ServiceImpl<CommentsMapper, Comments> {


    @Resource
    private CommentsMapper commentsMapper;
    public List<Comments> getCommentsByMovieId(int movieId) {
        QueryWrapper<Comments> commentsQueryWrapper = new QueryWrapper<>();
        commentsQueryWrapper.eq("movie_id", movieId);
        return commentsMapper.selectList(commentsQueryWrapper);
    }


    @Transactional
    public void addComment(Comments comment) {
        long currentTimeMillis = System.currentTimeMillis();
        comment.setCreatedDate(new Date(currentTimeMillis));
        commentsMapper.insert(comment);
    }
}
